import spock.lang.Specification
import spock.lang.Unroll

/**
 *
 * Created by houjinxin on 17-3-31.
 */
class DataDrivenSpec extends Specification{

    @Unroll
    "max num of #a and #b is #c"(){
        expect:
            Math.max(a, b) == c

        where:
            a << [3, 4, 5]
            b << [5, 6, 9]
            c << [5, 6, 9]
    }

    @Unroll
    "minimum of #a and #b is #c"() {
        expect:
            Math.min(a, b) == c

        where:
            a | b || c
            3 | 7 || 3
            5 | 4 || 4
            9 | 9 || 9
    }

    @Unroll
    def "#person.name is a #sex.toLowerCase() person"() {
        expect:
            person.sex == sex

        where:
            person                    || sex
            new Person(name: "Fred")  || "Male"
            new Person(name: "Wilma") || "Female"
    }

    static class Person {
        String name
        String getSex() {
            name == "Fred" ? "Male" : "Female"
        }
    }
}
